package com.qf.openapi2204.zuul.consumer;

import com.qf.openapi2204.common.mqbean.RoutingInfoMqBean;
import com.qf.openapi2204.zuul.localcache.LocalCache;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.HashMap;

@Component
public class RoutingInfoConsumer {

    @RabbitListener(queues = "openapi-routing-queue")
    public void getRoutingInfo(RoutingInfoMqBean mqBean, Channel channel, Message message) throws IOException {

        System.out.println(mqBean);

        //1. 获取 操作类型
        String type = mqBean.getType();

        //2. 根据操作类型进行响应的操作
        if (type.equals("update")){

            String key = mqBean.getKey();
            HashMap<String, Object> data = mqBean.getData();
            LocalCache.routingCache.put(key,data);

        }else if(type.equals("delete")){

        }else if(type.equals("add")){

        }

        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
